package mamikeji.liaowa.ui.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;

import java.util.ArrayList;
import java.util.List;

import mamikeji.liaowa.R;
import mamikeji.liaowa.bean.DayRecommendedArticleBean;

/**
 * Created by 廉冲-android开发 on 2017/5/17.
 */
public class Wa_Msg_ArticleAdapter extends BaseAdapter {
    List<DayRecommendedArticleBean.DataEntity> mList = new ArrayList<>();
    LayoutInflater inflater;
    Context context;

    public Wa_Msg_ArticleAdapter() {
    }

    public Wa_Msg_ArticleAdapter(List<DayRecommendedArticleBean.DataEntity> mList, Context context) {
        this.mList = mList;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    public void setList(List<DayRecommendedArticleBean.DataEntity> mList) {
        this.mList = mList;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_wa_msg_list, null);
            viewHolder = new ViewHolder();

            viewHolder.textView_wa_msg_article_title = (TextView) convertView.findViewById(R.id.textView_wa_msg_article_title);
            viewHolder.textView_wa_msg_article_content = (TextView) convertView.findViewById(R.id.textView_wa_msg_article_content);
            viewHolder.imageView_wa_msg_article_img = (SimpleDraweeView) convertView.findViewById(R.id.imageView_wa_msg_article_img);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        DayRecommendedArticleBean.DataEntity dataEntity = (DayRecommendedArticleBean.DataEntity) getItem(position);

        viewHolder.textView_wa_msg_article_title.setText(dataEntity.getTitle());
        viewHolder.textView_wa_msg_article_content.setText(dataEntity.getContent());
        viewHolder.imageView_wa_msg_article_img.setImageURI(Uri.parse(dataEntity.getImgurl()));
        return convertView;
    }

    public class ViewHolder {
        TextView textView_wa_msg_article_title;
        TextView textView_wa_msg_article_content;
        SimpleDraweeView imageView_wa_msg_article_img;
    }
}
